import wepy from 'wepy'


export default class extends wepy.mixin {

  data = {
    secondCateList: [],
    // 屏幕可用高度
    wh: 0,
    // 徽章
    active: 0,
    catesList: []
  }

  onLoad() {
    this.getCateData()
    this.getHeight()
    //console.log(this.catesList)
  }

  methods = {
    goGoodsList(paramId){
      //console.log(paramId)
      wepy.navigateTo({
        url:'/pages/goods_list?cid='+paramId
      })
    },
    onChange(e) {
      this.secondCateList = this.catesList[e.detail].children
      this.$apply();
      //console.log(this.secondCateList)
    }
  }
  // 获取屏幕可用高度
  async getHeight() {
    var res = await wepy.getSystemInfo()
    if (res.errMsg == "getSystemInfo:ok")
      this.wh = res.windowHeight
    this.$apply();
  }
  // 获取分类数据
  async getCateData() {
    var { data: res } = await wepy.get(`/categories`)
    if (res.meta.status != 200) return wepy.baseToast()
    this.catesList = res.message
    this.secondCateList = res.message[0].children
    this.$apply();
  }
}